package model.tests;

import static org.junit.Assert.assertTrue;

import java.util.Collection;

import model.collisions.Collisionable;
import model.elements.Element2D;
import model.elements.PlayerCharacter;
import model.elements.Wall;
import model.elements.attributes.Coordinate2D;
import model.exceptions.ModelExceptions;
import model.extra.SimplePositionablesContainer;
import model.map.PositionablesContainer;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;



// TODO: Auto-generated Javadoc
/**
 * The Class ElementsDatabaseTest.
 */
public class ElementsDatabaseTest 
{
	
	/** The database. */
	private PositionablesContainer database = new SimplePositionablesContainer();

	/**
	 * Sets the up.
	 *
	 * @throws Exception the exception
	 */
	@Before
	public void setUp() throws Exception {}

	/**
	 * Tear down.
	 *
	 * @throws Exception the exception
	 */
	@After
	public void tearDown() throws Exception 
	{		
		database.clear();
	}

	/**
	 * Test remove element.
	 *
	 * @throws ModelExceptions the model exceptions
	 */
	@Test
	public void testRemoveElement() throws ModelExceptions 
	{
		
		PlayerCharacter elemento1 = new PlayerCharacter( new Coordinate2D() );
		PlayerCharacter elemento2 = new PlayerCharacter( new Coordinate2D() );
		
		database.addElement(elemento1);
		database.addElement(elemento2);
		
		database.removeElement(elemento2);
		
		assertTrue( database.getElementCount() == 1 );
		assertTrue( database.getElementsIn( new Coordinate2D() ).contains( elemento1 ) );
		
	}
	
	/**
	 * Test get elements in.
	 *
	 * @throws ModelExceptions the model exceptions
	 */
	@Test
	public void testGetElementsIn() throws ModelExceptions 
	{
		
		Element2D elemento1 = new Wall( new Coordinate2D(0,0) );
		Element2D elemento2 = new Wall( new Coordinate2D(1,0) );
		Element2D elemento3 = new Wall( new Coordinate2D(0,0) );
		
		database.addElement(elemento1);
		database.addElement(elemento2);
		database.addElement(elemento3);
		
		Collection<Collisionable> testList = database.getElementsIn( new Coordinate2D(0,0) );
		
		assertTrue( testList.size() == 2 );
		
	}

}
